//
//  WmcArticulationBtn.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/7/7.
//

import UIKit
import YPGraphicEngine

extension YPGEVideoBuffer.Articulation {}

// MARK: - [WmcArticulationBtn]

class WmcArticulationBtn: WmcTopImgBottomTextBtn {
    /// 事件Block
    var actionBlock: YPBlock.Action<WmcArticulationBtn>?

//    lazy var pLabel: UILabel = {
//        let label = UILabel.YP.Create(font: 11.yp.uiFont(weight: .bold),
//                                      color: UIColor.white, alignment: .center)
//        return label
//    }()
//
//    lazy var tagLabel: UILabel = {
//        let label = UILabel.YP.Create(font: 10, color: UIColor.white, alignment: .center)
//        label.backgroundColor = UIColor.white.yp.alpha(0.2)
//        label.layer.cornerRadius = 2
//        label.layer.masksToBounds = true
//        return label
//    }()
//
//    lazy var titleLabel: UILabel = {
//        let label = UILabel.YP.Create(text: "视频画质", font: 12, color: UIColor.white, alignment: .center)
//        return label
//    }()

    /// 画幅比例类型
    var articulation: YPGEVideoBuffer.Articulation = ._720p {
        didSet {
//            pLabel.text = "\(articulation.info.row_p)P"
//            tagLabel.text = articulation.info.name
            switch articulation {
            case ._1080p:
                imageView.image = "icon_articulation_1080P".wmc_image.yp.setTemplateMode()
            case ._720p:
                imageView.image = "icon_articulation_720P".wmc_image.yp.setTemplateMode()
            case ._540p:
                imageView.image = "icon_articulation_540P".wmc_image.yp.setTemplateMode()
            default:
                imageView.image = nil
            }
        }
    }

//    func setTintColor(_ color: UIColor) {
//        pLabel.textColor = color
//        tagLabel.textColor = color
//        tagLabel.backgroundColor = color.yp.alpha(0.2)
//        titleLabel.textColor = color
//    }
    
    
    /// 创建
    static func Create() -> WmcArticulationBtn {
        let btn = WmcArticulationBtn()
        btn.title = "清晰度"
        btn.font = 12.wmc_font
        btn.imgTextSpacing = 2
        btn.imgSize = 24
        btn.textColor = UIColor.wmc_grayH5_606066
        btn.yp.addEvent { btn in
            btn.clickArticulation()
            btn.actionBlock?(btn)
        }
        btn.articulation = ._720p
        return btn
    }

    /// 递增事件
    func clickArticulation() {
        let new = articulation.rawValue
        if let newCase = YPGEVideoBuffer.Articulation(rawValue: new + 1) {
            articulation = newCase
        } else {
            articulation = ._540p
        }
    }

//    override func makeUI() {
//        addSubview(pLabel)
//        pLabel.snp.makeConstraints { make in
//            make.top.left.right.equalToSuperview()
//            make.height.equalTo(10)
//        }
//
//        addSubview(tagLabel)
//        tagLabel.snp.makeConstraints { make in
//            make.top.equalTo(pLabel.snp.bottom).offset(2)
//            make.height.equalTo(13)
//            make.centerX.equalToSuperview()
//            make.width.equalTo(27)
//        }
//
//        addSubview(titleLabel)
//        titleLabel.snp.makeConstraints { make in
//            make.top.equalTo(tagLabel.snp.bottom)
//            make.left.right.bottom.equalToSuperview()
//        }
//    }
}
